<?php namespace Admin\Controller; 
use Hdphp\Controller\Controller;
class LoginController extends Controller{
	
	private $sc_adminModel;
	public function __init(){
		$this->sc_adminModel=M('\Common\Model\sc_admin');
	}
	
	
		
	public function index(){
		//判断是否提交数据
		if(IS_POST){
			$code=Q('code',Null,'strtoupper');
			$adminname=Q('username',null,'strtolower');
			$adminpwd=Q('password',null,'md5');
		   //判断验证码
			if($code!==$_SESSION['code']) View::error('验证码错误');
			
			//判断用户名是否存在
			$adminData=$this->sc_adminModel->getAdmin($adminname,$adminpwd);
			if(!$adminData) View::error('用户名或密码有误');
			
			//写入session
			$_SESSION['info']=[
			    'username'=>$adminname,
			    'uid'=>$adminData['aid'],
			];
			
			View::success('登录成功！',U('Index/index'));

		}

		View::make();
   
	}	
	
	
	public function code(){
		Code::fontSize(20)->height(45)->width(130)->num(1)->make();
	}
	
}
	
?>